##########################################

# To reproduce the dataset used in Davide MORISI, Héloïse CLOLERY, Guillaume KON KAM KING, and Max SCHAUB. (Forthcoming). “How COVID-19 affects voting for incumbents: Evidence from local elections in France.” PlosOne (2024-01-17), please run

# > make -j10 Results/MAP_estimated_hz_infect_2021_01_18.csv

# The number 10 may be replaced by the desired number of threads.

# NB: Most optimisations are run several times independently and the best result is selected. Independent runs are denoted by the suffix "rep"

#The main dependencies are:
#- the rstan package and the Stan software
#- R with the tidyverse packages
#- the readstata package

# Population data extrapolation

Results/Population_data_extrapolated.rds: Scripts/predicting_future_population.Rmd Data/Municipality_data.dta
	Rscript -e "rmarkdown::render('Scripts/predicting_future_population.Rmd')"


# No age and sex effect 2021_01_18

Results/stan_data_for_fit_2021_01_18.rds: Scripts/prepare_stan_data_for_fit_2021_01_18.R Data/Municipality_data_2021_01_18.csv Results/Population_data_extrapolated.rds
	Rscript Scripts/prepare_stan_data_for_fit_2021_01_18.R

Results/vb_estimated_shrunk_hazard_rate_2021_01_18_rep1.rds: Results/stan_data_for_fit_2021_01_18.rds Scripts/hazard_rate_vb_estimation_2021_01_18_lasso.R Scripts/Poisson_model_lasso.stan
	Rscript Scripts/hazard_rate_vb_estimation_2021_01_18_lasso.R 5 rep1 > Results/vb_estimated_shrunk_hazard_rate_2021_01_18_rep1.log
	
Results/vb_estimated_shrunk_hazard_rate_2021_01_18_rep2.rds: Results/stan_data_for_fit_2021_01_18.rds Scripts/hazard_rate_vb_estimation_2021_01_18_lasso.R Scripts/Poisson_model_lasso.stan
	Rscript Scripts/hazard_rate_vb_estimation_2021_01_18_lasso.R 15 rep2 > Results/vb_estimated_shrunk_hazard_rate_2021_01_18_rep2.log

vb_estimated_shrunk_hazard_rate_2021_01_18: Results/vb_estimated_shrunk_hazard_rate_2021_01_18_rep1.rds Results/vb_estimated_shrunk_hazard_rate_2021_01_18_rep2.rds

Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_rep1.rds: Results/vb_estimated_shrunk_hazard_rate_2021_01_18_rep1.rds Scripts/hazard_rate_MAP_estimation_2021_01_18_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_2021_01_18_lasso.R Results/vb_estimated_shrunk_hazard_rate_2021_01_18_rep1.rds > Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_rep1.log

Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_rep2.rds: Results/vb_estimated_shrunk_hazard_rate_2021_01_18_rep2.rds Scripts/hazard_rate_MAP_estimation_2021_01_18_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_2021_01_18_lasso.R Results/vb_estimated_shrunk_hazard_rate_2021_01_18_rep2.rds > Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_rep2.log

MAP_estimated_shrunk_hazard_rate_2021_01_18: Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_rep1.rds Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_rep2.rds

# No age and sex effect 2021_01_18 4 week

Results/stan_data_for_fit_2021_01_18_4weeks.rds: Scripts/prepare_stan_data_for_fit_2021_01_18_4weeks.R Data/Municipality_data_2021_01_18.csv Results/Population_data_extrapolated.rds
	Rscript Scripts/prepare_stan_data_for_fit_2021_01_18_4weeks.R

Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep1.rds: Results/stan_data_for_fit_2021_01_18_4weeks.rds Scripts/hazard_rate_vb_estimation_lasso.R Scripts/Poisson_model_lasso.stan
	Rscript Scripts/hazard_rate_vb_estimation_lasso.R stan_data Results/stan_data_for_fit_2021_01_18_4weeks.rds saveto Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep1 seed 5 > Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep1.log


Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep2.rds: Results/stan_data_for_fit_2021_01_18_4weeks.rds Scripts/hazard_rate_vb_estimation_lasso.R Scripts/Poisson_model_lasso.stan
	Rscript Scripts/hazard_rate_vb_estimation_lasso.R stan_data Results/stan_data_for_fit_2021_01_18_4weeks.rds saveto Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep2 seed 15 > Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep2.log
		

vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks: Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep1.rds Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep2.rds

Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep1.rds: Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep1.rds Scripts/hazard_rate_MAP_estimation_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_lasso.R vb_input Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep1.rds > Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep1.log

Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep2.rds: Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep2.rds Scripts/hazard_rate_MAP_estimation_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_lasso.R vb_input Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep2.rds > Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep2.log

MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks: Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep1.rds Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_rep2.rds


# No age and sex effect 2021_01_18 second round

Results/stan_data_for_fit_2021_01_18_second_round.rds: Scripts/prepare_stan_data_for_fit_2021_01_18_second_round.R Data/Municipality_data_2021_01_18.csv Results/Population_data_extrapolated.rds
	Rscript Scripts/prepare_stan_data_for_fit_2021_01_18_second_round.R

Results/vb_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds: Results/stan_data_for_fit_2021_01_18_second_round.rds Scripts/hazard_rate_vb_estimation_2021_01_18_second_round_lasso.R Scripts/Poisson_model_lasso.stan
	Rscript Scripts/hazard_rate_vb_estimation_2021_01_18_second_round_lasso.R 6 rep1 > Results/vb_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep1.log
	
Results/vb_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep2.rds: Results/stan_data_for_fit_2021_01_18_second_round.rds Scripts/hazard_rate_vb_estimation_2021_01_18_second_round_lasso.R Scripts/Poisson_model_lasso.stan
	Rscript Scripts/hazard_rate_vb_estimation_2021_01_18_second_round_lasso.R 2 rep2 > Results/vb_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep2.log

vb_estimated_shrunk_hazard_rate_2021_01_18_second_round: Results/vb_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds Results/vb_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep2.rds

Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds: Results/vb_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds Scripts/hazard_rate_MAP_estimation_2021_01_18_second_round_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_2021_01_18_second_round_lasso.R Results/vb_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds > Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep1.log

Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep2.rds: Results/vb_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep2.rds Scripts/hazard_rate_MAP_estimation_2021_01_18_second_round_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_2021_01_18_second_round_lasso.R Results/vb_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep2.rds > Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep2.log

MAP_estimated_shrunk_hazard_rate_2021_01_18_second_round: Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep2.rds


# No age and sex effect 2021_01_18 4 week second round

Results/stan_data_for_fit_2021_01_18_4weeks_second_round.rds: Scripts/prepare_stan_data_for_fit_2021_01_18_4weeks_second_round.R Data/Municipality_data_2021_01_18.csv Results/Population_data_extrapolated.rds
	Rscript Scripts/prepare_stan_data_for_fit_2021_01_18_4weeks_second_round.R

Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.rds: Results/stan_data_for_fit_2021_01_18_4weeks_second_round.rds Scripts/hazard_rate_vb_estimation_lasso.R Scripts/Poisson_model_lasso.stan
	Rscript Scripts/hazard_rate_vb_estimation_lasso.R stan_data Results/stan_data_for_fit_2021_01_18_4weeks.rds saveto Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1 seed 5 > Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.log


Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.rds: Results/stan_data_for_fit_2021_01_18_4weeks_second_round.rds Scripts/hazard_rate_vb_estimation_lasso.R Scripts/Poisson_model_lasso.stan
	Rscript Scripts/hazard_rate_vb_estimation_lasso.R stan_data Results/stan_data_for_fit_2021_01_18_4weeks.rds saveto Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2 seed 15 > Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.log

vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks: Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.rds Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.rds

Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.rds: Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.rds Scripts/hazard_rate_MAP_estimation_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_lasso.R vb_input Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.rds > Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.log

Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.rds: Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.rds Scripts/hazard_rate_MAP_estimation_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_lasso.R vb_input Results/vb_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.rds > Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.log

MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round: Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.rds Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.rds


# Age and sex effect shrinkage 2021_01_18

Results/stan_data_for_fit_age_sex_2021_01_18.rds: Scripts/prepare_stan_data_for_fit_age_sex_2021_01_18.R Data/Municipality_data_2021_01_18.csv Results/Population_data_extrapolated.rds Data/age_sex_specific_mortality_rates.csv Scripts/prepare_population_data.R Data/Census_data.dta
	Rscript Scripts/prepare_stan_data_for_fit_age_sex_2021_01_18.R 


Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep1.rds: Results/stan_data_for_fit_age_sex_2021_01_18.rds Scripts/hazard_rate_vb_estimation_2021_01_18_age_sex_structure_lasso.R Scripts/Poisson_model_age_sex_effect_nu_shrunk.stan
	Rscript Scripts/hazard_rate_vb_estimation_2021_01_18_age_sex_structure_lasso.R 11 rep1 > Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep1.log
	
Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep2.rds: Results/stan_data_for_fit_age_sex_2021_01_18.rds Scripts/hazard_rate_vb_estimation_2021_01_18_age_sex_structure_lasso.R  Scripts/Poisson_model_age_sex_effect_nu_shrunk.stan 
	Rscript Scripts/hazard_rate_vb_estimation_2021_01_18_age_sex_structure_lasso.R 4 rep2 > Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep2.log
	
Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep3.rds: Results/stan_data_for_fit_age_sex_2021_01_18.rds Scripts/hazard_rate_vb_estimation_2021_01_18_age_sex_structure_lasso.R  Scripts/Poisson_model_age_sex_effect_nu_shrunk.stan 
	Rscript Scripts/hazard_rate_vb_estimation_2021_01_18_age_sex_structure_lasso.R 21 rep3 > Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep3.log
	
vb_shrinkage_estimations: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep1.rds Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep2.rds Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep3.rds

Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep1.rds: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep1.rds Results/stan_data_for_fit_age_sex_2021_01_18.rds Scripts/hazard_rate_MAP_estimation_2021_01_18_age_sex_structure_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_2021_01_18_age_sex_structure_lasso.R Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep1.rds > Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep1.log

Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep2.rds: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep2.rds Results/stan_data_for_fit_age_sex_2021_01_18.rds Scripts/hazard_rate_MAP_estimation_2021_01_18_age_sex_structure_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_2021_01_18_age_sex_structure_lasso.R Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep2.rds > Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep2.log

Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep3.rds: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep3.rds Results/stan_data_for_fit_age_sex_2021_01_18.rds Scripts/hazard_rate_MAP_estimation_2021_01_18_age_sex_structure_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_2021_01_18_age_sex_structure_lasso.R Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep3.rds > Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep3.log

MAP_shrinkage_estimations_age_sex_2021_01_18: Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep1.rds Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep2.rds Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep3.rds

# Age and sex effect shrinkage 2021_01_18 4 weeks

Results/stan_data_for_fit_age_sex_2021_01_18_4weeks.rds: Scripts/prepare_stan_data_for_fit_age_sex_2021_01_18_4weeks.R Data/Municipality_data_2021_01_18.csv Results/Population_data_extrapolated.rds Data/Census_data.dta Data/age_sex_specific_mortality_rates.csv Scripts/prepare_population_data.R
	Rscript Scripts/prepare_stan_data_for_fit_age_sex_2021_01_18_4weeks.R 

Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep1.rds: Results/stan_data_for_fit_age_sex_2021_01_18_4weeks.rds Scripts/hazard_rate_vb_estimation_age_sex_structure_lasso.R Scripts/Poisson_model_age_sex_effect_nu_shrunk.stan
	Rscript Scripts/hazard_rate_vb_estimation_age_sex_structure_lasso.R stan_data Results/stan_data_for_fit_age_sex_2021_01_18_4weeks.rds saveto Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep1 seed 4 > Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep1.log
	
Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep2.rds: Results/stan_data_for_fit_age_sex_2021_01_18_4weeks.rds Scripts/hazard_rate_vb_estimation_age_sex_structure_lasso.R Scripts/Poisson_model_age_sex_effect_nu_shrunk.stan
	Rscript Scripts/hazard_rate_vb_estimation_age_sex_structure_lasso.R stan_data Results/stan_data_for_fit_age_sex_2021_01_18_4weeks.rds saveto Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep2 seed 11 > Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep2.log
	
Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep3.rds: Results/stan_data_for_fit_age_sex_2021_01_18_4weeks.rds Scripts/hazard_rate_vb_estimation_age_sex_structure_lasso.R Scripts/Poisson_model_age_sex_effect_nu_shrunk.stan
	Rscript Scripts/hazard_rate_vb_estimation_age_sex_structure_lasso.R stan_data Results/stan_data_for_fit_age_sex_2021_01_18_4weeks.rds saveto Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep3 seed 21 > Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep3.log
	
vb_shrinkage_estimations_4weeks: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep1.rds Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep2.rds Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep3.rds


Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep1.rds: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep1.rds  Scripts/hazard_rate_MAP_estimation_age_sex_structure_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_age_sex_structure_lasso.R  vb_input Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep1.rds  > Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep1.log

Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep2.rds: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep2.rds  Scripts/hazard_rate_MAP_estimation_age_sex_structure_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_age_sex_structure_lasso.R  vb_input Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep2.rds  > Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep2.log

Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep3.rds: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep3.rds  Scripts/hazard_rate_MAP_estimation_age_sex_structure_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_age_sex_structure_lasso.R  vb_input Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep3.rds  > Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep3.log

MAP_shrinkage_estimations_age_sex_2021_01_18_4weeks: Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep1.rds Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep2.rds Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_rep3.rds

# Age and sex effect shrinkage 2021_01_18 second round

Results/stan_data_for_fit_age_sex_2021_01_18_second_round.rds: Scripts/prepare_stan_data_for_fit_age_sex_2021_01_18_second_round.R Data/Municipality_data_2021_01_18.csv Results/Population_data_extrapolated.rds Data/Census_data.dta Data/age_sex_specific_mortality_rates.csv Scripts/prepare_population_data.R
	Rscript Scripts/prepare_stan_data_for_fit_age_sex_2021_01_18_second_round.R 


Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds: Results/stan_data_for_fit_age_sex_2021_01_18_second_round.rds Scripts/hazard_rate_vb_estimation_2021_01_18_second_round_age_sex_structure_lasso.R  Scripts/Poisson_model_age_sex_effect_nu_shrunk.stan
	Rscript Scripts/hazard_rate_vb_estimation_2021_01_18_second_round_age_sex_structure_lasso.R 11 rep1 > Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep1.log
	
Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep2.rds: Results/stan_data_for_fit_age_sex_2021_01_18_second_round.rds Scripts/hazard_rate_vb_estimation_2021_01_18_second_round_age_sex_structure_lasso.R  Scripts/Poisson_model_age_sex_effect_nu_shrunk.stan
	Rscript Scripts/hazard_rate_vb_estimation_2021_01_18_second_round_age_sex_structure_lasso.R 16 rep2 > Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep2.log
	
Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep3.rds: Results/stan_data_for_fit_age_sex_2021_01_18_second_round.rds Scripts/hazard_rate_vb_estimation_2021_01_18_second_round_age_sex_structure_lasso.R  Scripts/Poisson_model_age_sex_effect_nu_shrunk.stan
	Rscript Scripts/hazard_rate_vb_estimation_2021_01_18_second_round_age_sex_structure_lasso.R 21 rep3 > Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep3.log
	
vb_shrinkage_estimations_age_sex_2021_01_18_second_round: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep2.rds Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep3.rds

Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds Results/stan_data_for_fit_age_sex_2021_01_18_second_round.rds Scripts/hazard_rate_MAP_estimation_2021_01_18_second_round_age_sex_structure_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_2021_01_18_second_round_age_sex_structure_lasso.R Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds > Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep1.log

Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep2.rds: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep2.rds Results/stan_data_for_fit_age_sex_2021_01_18_second_round.rds Scripts/hazard_rate_MAP_estimation_2021_01_18_second_round_age_sex_structure_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_2021_01_18_second_round_age_sex_structure_lasso.R Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep2.rds > Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep2.log

Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep3.rds: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep3.rds Results/stan_data_for_fit_age_sex_2021_01_18_second_round.rds Scripts/hazard_rate_MAP_estimation_2021_01_18_second_round_age_sex_structure_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_2021_01_18_second_round_age_sex_structure_lasso.R Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep3.rds > Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep3.log

MAP_shrinkage_estimations_age_sex_2021_01_18_second_round: Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep2.rds Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep3.rds

# Age and sex effect shrinkage 2021_01_18 4 weeks second round

Results/stan_data_for_fit_age_sex_2021_01_18_4weeks_second_round.rds: Scripts/prepare_stan_data_for_fit_age_sex_2021_01_18_4weeks_second_round.R Data/Municipality_data_2021_01_18.csv Results/Population_data_extrapolated.rds Data/Census_data.dta Data/age_sex_specific_mortality_rates.csv Scripts/prepare_population_data.R
	Rscript Scripts/prepare_stan_data_for_fit_age_sex_2021_01_18_4weeks_second_round.R 

Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.rds: Results/stan_data_for_fit_age_sex_2021_01_18_4weeks_second_round.rds Scripts/hazard_rate_vb_estimation_age_sex_structure_lasso.R Scripts/Poisson_model_age_sex_effect_nu_shrunk.stan
	Rscript Scripts/hazard_rate_vb_estimation_age_sex_structure_lasso.R stan_data Results/stan_data_for_fit_age_sex_2021_01_18_4weeks_second_round.rds saveto Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1 seed 4 > Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.log
	
Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.rds: Results/stan_data_for_fit_age_sex_2021_01_18_4weeks_second_round.rds Scripts/hazard_rate_vb_estimation_age_sex_structure_lasso.R Scripts/Poisson_model_age_sex_effect_nu_shrunk.stan
	Rscript Scripts/hazard_rate_vb_estimation_age_sex_structure_lasso.R stan_data Results/stan_data_for_fit_age_sex_2021_01_18_4weeks_second_round.rds saveto Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2 seed 11 > Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.log
	
Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep3.rds: Results/stan_data_for_fit_age_sex_2021_01_18_4weeks_second_round.rds Scripts/hazard_rate_vb_estimation_age_sex_structure_lasso.R Scripts/Poisson_model_age_sex_effect_nu_shrunk.stan
	Rscript Scripts/hazard_rate_vb_estimation_age_sex_structure_lasso.R stan_data Results/stan_data_for_fit_age_sex_2021_01_18_4weeks_second_round.rds saveto Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep3 seed 21 > Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep3.log
	
vb_shrinkage_estimations_4weeks_second_round: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.rds Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.rds Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep3.rds

Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.rds: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.rds  Scripts/hazard_rate_MAP_estimation_age_sex_structure_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_age_sex_structure_lasso.R  vb_input Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.rds  > Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.log

Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.rds: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.rds  Scripts/hazard_rate_MAP_estimation_age_sex_structure_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_age_sex_structure_lasso.R  vb_input Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.rds  > Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.log

Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep3.rds: Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep3.rds  Scripts/hazard_rate_MAP_estimation_age_sex_structure_lasso.R
	Rscript Scripts/hazard_rate_MAP_estimation_age_sex_structure_lasso.R  vb_input Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep3.rds  > Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep3.log

MAP_shrinkage_estimations_age_sex_2021_01_18_4weeks_second_round: Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep1.rds Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep2.rds Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_4weeks_second_round_rep3.rds
	
######## Create final excess mortality estimation dataset 

Results/MAP_estimated_hz_infect_2021_01_18.csv: Scripts/combine_into_final_dataset.R Data/Municipality_data_2021_01_18.csv Results/Population_data_extrapolated.rds Results/vb_estimated_shrunk_hazard_rate_2021_01_18_rep2.rds Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_rep2.rds Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep1.rds Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_rep1.rds Results/vb_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds Results/MAP_estimated_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds Results/vb_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds Results/MAP_estimated_age_sex_structure_shrunk_hazard_rate_2021_01_18_second_round_rep1.rds
	Rscript Scripts/combine_into_final_dataset.R

#NB also creating Results/MAP_estimated_hz_infect_2021_01_18_second_round.csv
